package com.ssly.media.manage.service;

import com.ssly.media.manage.domain.SourceMedia;
import com.ssly.media.manage.ffmpeg.Media;
import com.ssly.media.manage.repository.DownTaskRepository;
import com.ssly.media.manage.repository.SourceMediaRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.xml.soap.Name;
import java.io.File;
import java.nio.file.Paths;
import java.sql.Timestamp;

@Service
public class SourceMediaService {
    private final SourceMediaRepository sourceMediaRepository;


    @Autowired
    public SourceMediaService(SourceMediaRepository sourceMediaRepository) {
        this.sourceMediaRepository = sourceMediaRepository;
    }


    public SourceMedia create(File mediaFile, String name){
        Media media = new Media(mediaFile);
        SourceMedia sourceMedia = new SourceMedia();
        sourceMedia.setName(name);
        sourceMedia.setSavePath(mediaFile.getAbsolutePath());
        sourceMedia.setAcodec(media.getAcodec());
        sourceMedia.setVcodec(media.getVcodec());
        sourceMedia.setBitrate(media.getBitrate());
        sourceMedia.setDuration(media.getDuration());
        sourceMedia.setWidth(media.getWidth());
        sourceMedia.setHeight(media.getHeight());
        sourceMedia.setFps(media.getFps());
        sourceMedia.setLenght(media.getLenght());
        sourceMedia.setCreateTime(new Timestamp(System.currentTimeMillis()));
        return  sourceMediaRepository.save(sourceMedia);
    }
}
